//
//  HXTabBarController.m
//  爱鲜蜂
//
//  Created by 洪东恒 on 16/4/3.
//  Copyright © 2016年 建国. All rights reserved.
//
#import "HXNavController.h"
#import "HXTabBarController.h"
#import "HXHomeViewController.h"
#import "HXMineController.h"
#import "HXMarketViewController.h"
#import "HXShopCarViewController.h"
@interface HXTabBarController ()

@end

@implementation HXTabBarController

//设置tabbar下标文字的大小
+(void)load
{
    UITabBarItem *tabbar =[UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[self]];
    //设置文字不渲染
    NSMutableDictionary *dictColor = [NSMutableDictionary dictionary];
    dictColor[NSForegroundColorAttributeName] = [UIColor redColor];
    
    [tabbar setTitleTextAttributes:dictColor forState:UIControlStateSelected];
    
    //设置文字普通状态下的大小
    NSMutableDictionary *dictFont = [NSMutableDictionary dictionary];
    dictFont[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    [tabbar setTitleTextAttributes:dictFont forState:UIControlStateNormal];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self addChildController];
}

-(void)addChildController
{
    //添加Home首页 控制器 添加到nav导航控制器中
  

    HXHomeViewController *home = [[HXHomeViewController alloc]init];
    HXNavController *navHome = [[HXNavController alloc]initWithRootViewController:home];
    //设置标题
    navHome.tabBarItem.title = @"首页";
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor blackColor];
    [navHome.tabBarItem setTitleTextAttributes:dict forState:(UIControlStateSelected)];
    //设置图片
    navHome.tabBarItem.image = [UIImage imageNamed:@"v2_home"];
    navHome.tabBarItem.selectedImage = [UIImage imageNamed:@"v2_home_r"];
    
    //设置颜色
    home.view.backgroundColor = [UIColor whiteColor];
    //添加到tabbar控制器中
    [self addChildViewController:navHome];
    
    
    //添加超市 控制器 添加到nav导航控制器中
    HXMarketViewController *mark = [[HXMarketViewController alloc]init];
    HXNavController *navMake = [[HXNavController alloc]initWithRootViewController:mark];
    //设置标题
    navMake.tabBarItem.title = @"闪电超市";
    //设置图片
    navMake.tabBarItem.image = [UIImage imageNamed:@"v2_order"];
    navMake.tabBarItem.selectedImage = [UIImage imageNamed:@"v2_order_r"];
    //设置颜色
    mark.view.backgroundColor = [UIColor orangeColor];
    //添加到tabbar控制器中
    [self addChildViewController:navMake];
    
    
    //添加购物车 控制器 添加到nav导航控制器中
    HXShopCarViewController *shop = [[HXShopCarViewController alloc]init];
    HXNavController *navshop = [[HXNavController alloc]initWithRootViewController:shop];
    //设置标题
    navshop.tabBarItem.title = @"购物车";
    //设置图片
    navshop.tabBarItem.image = [UIImage imageNamed:@"shopCart"];
    navshop.tabBarItem.selectedImage = [UIImage imageNamed:@"shopCart_r"];
    //设置颜色
//    shop.view.backgroundColor = [UIColor greenColor];
    //添加到tabbar控制器中
    [self addChildViewController:navshop];
    
    
    //添加我的 控制器 添加到nav导航控制器中
    HXMineController *mine = [[HXMineController alloc]init];
    HXNavController *navMine = [[HXNavController alloc]initWithRootViewController:mine];
    //设置标题
    navMine.tabBarItem.title = @"我的";
    //设置图片
    navMine.tabBarItem.image = [UIImage imageNamed:@"v2_my"];
    navMine.tabBarItem.selectedImage = [UIImage imageNamed:@"v2_my_r"];
    //设置颜色
    mine.view.backgroundColor = [UIColor redColor];
    //添加到tabbar控制器中
    [self addChildViewController:navMine];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
